//
//  XHBNavigationController.m
//  iOS Object
//
//  Created by 保密 on 2019/6/26.
//  Copyright © 2019年 XiaoHaiBao. All rights reserved.
//

#import "XHBNavigationController.h"

@interface XHBNavigationController ()

@end

@implementation XHBNavigationController

+ (void)load {
    
    UINavigationBar *navBar = [UINavigationBar appearance];
    /*
     UIBarStyleDefault          = 0, // 状态栏文字黑色
     UIBarStyleBlack            = 1, // 状态栏文字白色
     */
//    navBar.barStyle = UIBarStyleBlack;
    
    // 导航栏透明
    [navBar setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor]] forBarMetrics:UIBarMetricsDefault];
    
    
    // 设置标题栏文字样式
    [navBar setTitleTextAttributes:@{
                                     NSForegroundColorAttributeName:RGBColor(51, 51, 51),
                                     NSFontAttributeName:Font_PingFang_SC(17),
                                     }];
    
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.childViewControllers.count > 0) {
        
        viewController.hidesBottomBarWhenPushed = YES;
        
        // 就有滑动返回功能
        self.interactivePopGestureRecognizer.delegate = nil;
        
        //返回按钮自定义
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
        negativeSpacer.width = -15;
        
        UIButton *button = [[UIButton alloc] init];
        [button setImage:[UIImage imageNamed:@"nav_back_normal"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"nav_back_highlight"] forState:UIControlStateHighlighted];
        button.frame = CGRectMake(0, 0, 35, 35);
        
        if (@available(ios 11.0,*)) {
            button.contentEdgeInsets = UIEdgeInsetsMake(0, -5,0, 0);
            button.imageEdgeInsets = UIEdgeInsetsMake(0, -5,0, 0);
        }
        
        [button addTarget:self action:@selector(backButtonTapClick) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
        
        viewController.navigationItem.leftBarButtonItems = @[negativeSpacer, backButton];
    }
    [super pushViewController:viewController animated:animated];
}
#pragma mark - 点击
- (void)backButtonTapClick {
    
    [self popViewControllerAnimated:YES];
}
@end
